#pragma once
#ifndef NULL
	#define NULL 0
#endif

#include <assert.h>

template <typename TYPE>
class Asset 
{
private:
	char* m_cszFileName;
	TYPE Data;
public:
	Asset () : FileName(NULL), Data(NULL) {}
	Asset (char* a_FileName, TYPE a_Data) 
	{
		FileName = a_FileName;
		Data = a_Data;
	}
	const char* GetFileName() const {return m_cszFileName;}
	const TYPE GetData() const {return Data;}
	bool operator==(Asset<TYPE> A)
	{
		if(FileName == A.FileName && Data == A.Data)
			return true;
		return false;
	}
};

template <class TYPE>
class Library 
{
private:
	TemplateVector<Asset<TYPE>>* m_assetList;
public:

	Library()
	{
		m_assetList = new TemplateVector<Asset<TYPE>>;
	}
	~Library()
	{
		delete m_assetList;
	}


	/**
	  * Returns the index of the asset in the library
	  * Does not add the file if it already exists in the library
	  */
	const int AddAsset(Asset<TYPE> a_Asset) 
	{
		int index = IndexofAsset( a_Asset );
		if( index == -1 ) 
		{
			m_assetList->add( a_Asset );
			return m_assetList->indexOf( a_Asset );
		}
		else return index;
	}

	/**
	  *Returns the vector size
	  */
	const int GetSize() { return m_assetList->getSize(); }

	TYPE FindByFileName(char * File)
	{
		Asset<TYPE> A;
		for(int i = 0;i < m_assetList->size();i++) 
		{
			if(File == m_assetList->get(i).GetFileName())
			{
				return m_assetList->get(i).GetData();
			}
		}
		return A.GetData();
	}
	/**
	  *Basic Removal
	  */
	void RemoveAsset(Asset<TYPE> a_Asset) 
	{
		m_assetList->removeData( a_Asset );
	}
	void RemovebyIndex(int a_Index) 
	{
		m_assetList->remove(a_Index);
	}
	void RemovebyFile(char * FileName) 
	{
		for(int i = 0;i < m_assetList->size();i++) 
		{
			if(FileName == m_assetList->get(i).GetFileName())
			{
				m_assetList->remove(i);
				break;
			}
		}
	}

	/**
	  *Basic Get
	  */
	Asset<TYPE> GetAsset(int const & i) 
	{
		return m_assetList->get(i);
	}
	TYPE GetAssetData(int const & i) 
	{
		return ((Asset<TYPE>)m_assetList->get(i)).GetData();
	}

	/**
	  *Basic Find Index
	  */
	const int IndexofAsset(Asset<TYPE> const & a_Asset) const 
	{
		for(int i = 0;i < m_assetList->size();i++) 
		{
			if( a_Asset.GetFileName() == m_assetList->get(i).GetFileName() )
				return i;
		}
		return -1;
	}
};